package com.example.demo.system.controller;

import com.example.demo.system.entity.User;
import com.example.demo.system.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank;
import javax.validation.Valid;
/**
* @author 许久龙
* @since 2022-02-19
*/
@RestController
@RequestMapping("api")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/user")
    @ApiOperation("User查询单个")
    public ResultVO getUser(@RequestBody User user){
     ResultVO resultVO = userService.getUser(User user);
     return  resultVO;
   }

    @GetMapping("/user")
    @ApiOperation("User查询全部")
    public ResultVO getAllUser(){
        ResultVO resultVO = userService.getAllUser();
        return  resultVO;
    }

    @PostMapping("/user")
    @ApiOperation("User新增")
    public ResultVO add(@Valid @RequestBody User user) {
        ResultVO resultVO = userService.add(User user);
        return  resultVO;
    }

    @PutMapping("/user")
    @ApiOperation("User修改")
    public ResultVO update(@Valid @RequestBody User user) {
        ResultVO resultVO = userService.update(User user);
        returnresultVO;
    }


    @DeleteMapping(value = "/user/{ids}")
    @ApiOperation("User删除(单个条目)")
    public ResultVO remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        ResultVO resultVO = userService.remove(String ids);
        return resultVO;
    }
}
